import {
  getAdministrationLessonList,
  getAdministrationClassList,
  getAdministrationTeacherList,
  addAdminstrationnLesson,
  updateAdminstrationnLessonDate,
  removeAdminstrationnLessonDate,
  updateAdminstrationnLessonTeacher,
  getAdminstrationnTeacherList,
  getCampusList,
  checkLesson,
  batchAddLesson,
  publishLesson,
  addWorkTime,
  getTeacherWorkTime,
} from  '../../../service/api';
export default {
  namespace: 'administration3',
  state: {
    events: [],
    teacherList: [],
    classList: [],
    similarTeacherList: [],
    addLessonDateResponse: null,
    updateLessonResponse: null,
    removeLessonResponse: null,
    updateLessonTeacherResponse: null,
    campusList: [],
    checkLessonResponse: null,
    batchAddResponse: null,
    publishLessonResponse: null,
    response: 0,
    totalWorkTime: {},
  },

  effects: {
    *getTeacherList({ payload }, { call, put }) {
      const response = yield call(getAdministrationTeacherList, payload);
      yield put({
        type: 'r_teacherList',
        payload: response,
      });
    },
    *getTeacherLessonList({ payload }, { call, put }) {
      const response = yield call(getAdministrationLessonList, payload);
      yield put({
        type: 'r_teacherLessonList',
        payload: response,
      });
    },
    *getClassList({ payload }, { call, put }) {
      const response = yield call(getAdministrationClassList, payload);
      yield put({
        type: 'r_classList',
        payload: response,
      });
    },
    *addLesson({ payload }, { call, put }) {
      const response = yield call(addAdminstrationnLesson, payload);
      yield put({
        type: 'r_addLesson',
        payload: response,
      });
    },
    *updateLessonDate({ payload }, { call, put }) {
      const response = yield call(updateAdminstrationnLessonDate, payload);
      yield put({
        type: 'r_updateLessonDate',
        payload: response,
      });
    },
    *removeLesson({ payload }, { call, put }) {
      const response = yield call(removeAdminstrationnLessonDate, payload);
      yield put({
        type: 'r_removeLesson',
        payload: response,
      });
    },
    *updateLessonTeacher({ payload }, { call, put }) {
      const response = yield call(updateAdminstrationnLessonTeacher, payload);
      yield put({
        type: 'r_updateLessonTeacher',
        payload: response,
      });
    },
    *getSimilarLessonTeacher({ payload }, { call, put }) {
      const response = yield call(getAdminstrationnTeacherList, payload);
      yield put({
        type: 'r_similarTeacherList',
        payload: response,
      });
    },
    *getCampusList({ payload }, { call, put }) {
      const response = yield call(getCampusList, payload);
      yield put({
        type: 'r_campusList',
        payload: response,
      });
    },
    *checkLesson({ payload }, { call, put }) {
      const response = yield call(checkLesson, payload);
      yield put({
        type: 'r_checkLesson',
        payload: response,
      });
    },
    *batchAddLesson({ payload }, { call, put }) {
      const response = yield call(batchAddLesson, payload);
      yield put({
        type: 'r_batchAddLesson',
        payload: response,
      });
    },
    *publishLesson({ payload }, { call, put }) {
      const response = yield call(publishLesson, payload);
      yield put({
        type: 'r_publishLesson',
        payload: response,
      });
    },
    *addWorkTime({ payload }, { call, put }) {
      const response = yield call(addWorkTime, payload);
      yield put({
        type: 'r_addWorkTime',
        payload: response,
      });
    },
    *getTeacherWorkTime({ payload }, { call, put }) {
      const response = yield call(getTeacherWorkTime, payload);
      yield put({
        type: 'r_getTeacherWorkTime',
        payload: response,
      });
    },
  },

  reducers: {
    r_teacherLessonList(state, action) {
      return {
        ...state,
        events: action.payload.data,
      };
    },
    r_teacherList(state, action) {
      return {
        ...state,
        teacherList: action.payload.data,
      };
    },
    r_classList(state, action) {
      return {
        ...state,
        classList: action.payload.data,
      };
    },
    r_addLesson(state, action) {
      return {
        ...state,
        addLessonDateResponse: action.payload,
      };
    },
    r_updateLessonDate(state, action) {
      return {
        ...state,
        updateLessonResponse: action.payload,
      };
    },
    r_removeLesson(state, action) {
      return {
        ...state,
        removeLessonResponse: action.payload,
      };
    },
    r_updateLessonTeacher(state, action) {
      return {
        ...state,
        updateLessonTeacherResponse: action.payload,
      };
    },
    r_similarTeacherList(state, action) {
      return {
        ...state,
        similarTeacherList: action.payload.data,
      };
    },
    r_campusList(state, action) {
      return {
        ...state,
        campusList: action.payload.data,
      };
    },
    r_checkLesson(state, action) {
      return {
        ...state,
        checkLessonResponse: action.payload,
      };
    },
    r_batchAddLesson(state, action) {
      return {
        ...state,
        batchAddResponse: action.payload,
      };
    },
    r_publishLesson(state, action) {
      return {
        ...state,
        publishLessonResponse: action.payload,
      };
    },
    r_addWorkTime(state, { payload }) {
      state.response = payload.status;
      return {
        ...state,
      };
    },
    r_getTeacherWorkTime(state, { payload }) {
      state.totalWorkTime = payload.data;
      return {
        ...state,
      };
    },
  },
};
